/**
 * 菜单展现JS
 * 2008-2-27
 * @author Jacky Chen
 */

function linkURL(url){
	$("main").src = url; 
}
/**
 * 初始化
 * 2008-2-27
 * @author Jacky Chen
 */
window.onload = function(){
	FrontAction.getTreeMap(showMenue);
}

/**
 * 递归展示菜单
 * 2008-2-27
 * @author Jacky Chen
 * @param {Object} data
 */
function showMenue(data){
	if(data){
		var htmlStr = "<ul id=\"menuModel\" style=\"display:none\">";
		for(var i=0;i<data[0].length;i++){
			htmlStr += "<li width=\"76\" jsFunction=\"linkURL('"+data[0][i].url+"')\" id=\""+data[0][i].id+"\"><a href=\"javascript:void(0);\">"+data[0][i].menuname+"</a>";
			htmlStr += showChildMenue(data[0][i].id,data);
			htmlStr += "</li>";
		}
		htmlStr += "</ul>";
		$("menu_div").innerHTML = htmlStr;
		var menuModel = new DHTMLSuite.menuModel();
		DHTMLSuite.configObj.setCssPath("../themes/default/menu-for-applications/css/");					
		menuModel.addItemsFromMarkup('menuModel');
		menuModel.setMainMenuGroupWidth(00);	
		menuModel.init();
		
		var menuBar = new DHTMLSuite.menuBar();
		menuBar.addMenuItems(menuModel);
		menuBar.setTarget('menuDiv');
		
		menuBar.init();
		showInit(document.getElementById("DHTMLSuite_menuBar_arrow"+data[0][0].id));
	}
}

/**
 * 菜单初始化
 * 2008-2-27
 * @author Jacky Chen
 * @param {Object} data
 * @param {Object} divObj
 */
function showInit(divObj){
	var objectIndex = divObj.getAttribute('objectRef');
	var obj = DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[objectIndex];
	var parentId = divObj.id.replace(/[^0-9]/gi,'');		
	var state = obj.menuItem_objects[parentId].getState();
	if(state=='disabled')return;
	obj.menuBarState = !obj.menuBarState;
	if(!obj.menuBarState)obj.hideSubMenus();else{
		obj.hideSubMenus();
		//obj.__expandGroup(parentId);
	}	
}

/**
 * 递归展示菜单(递归子的)
 * 2008-2-27
 * @author Jacky Chen
 * @param {Object} pId
 * @param {Object} data
 */
function showChildMenue(pId,data){
	var htmlStr = "";
	if(data[pId]){
		htmlStr += "<ul width=\"200\">";
		for(var i=0;i<data[pId].length;i++){
			htmlStr += "<li width=\"76\" jsFunction=\"linkURL('"+data[pId][i].url+"')\" id=\""+data[pId][i].id+"\"><a href=\"javascript:void(0);\">"+data[pId][i].menuname+"</a>";
			htmlStr += showChildMenue(data[pId][i].id,data);
		}
		htmlStr += "</ul>";	
	}
	return htmlStr;
}